import { defineStore } from "pinia"
import { ChatRoom } from '../type/entity'


export const useChatRoomStore = defineStore('chatRoom', {
  // 推荐使用 完整类型推断的箭头函数
  state: () => {
    return {
      chatRooms: [] as ChatRoom[],
      nowChatRoom: {} as ChatRoom,
      chatRoomOperating: false
    }
  },
  actions: {
    setChatRooms(chatRooms:ChatRoom[]){
      this.chatRooms = chatRooms.map(cr => {
        cr.inAnimate = cr.outAnimate = false
        return cr
      })
    },
    addChatRooms(chatRoom:ChatRoom){
      chatRoom.inAnimate = chatRoom.outAnimate = false
      this.chatRooms.push(chatRoom)
    },
    rmChatRoom(id:string){
      this.chatRooms = this.chatRooms.filter(v => v.id != id)
    }
  }
})